<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>
<html>
<head>
  <%@ include file="/common/meta.jsp" %>
  <title>节点类型列表</title>

  <script type="text/javascript">
    var _path = "${_ctx}/flow/nodeType";
    $(function () {
      initLayout();
      $(window).resize(function () {
        initLayout();
      });

      $("#mainGrid").ligerGrid({
        columns: [
          {display: 'id', name: 'id', hide: true, width: 60},
          {display: '序号', width: 40, render: function (rowData, rowindex, value, column, rowid, page, pageSize) { return (page - 1) * pageSize + rowindex + 1; }},
          {display: '类型编码', name: 'code', align: 'left', width: 80},
          {display: '类型名称', name: 'typeName', align: 'left', width: 120},
          {display: '解析器路径', name: 'nodeConverterClass', align: 'left', width: 360},
          {display: '编辑时间', name: 'editDate', align: 'right', width: 150},
          {display: '编辑人', name: 'editWho', align: 'left', width: 80}
        ], sortName: "code", sortOrder: "asc", url: _path + "/list/json?rnd=" + Math.random(),
        width: '100%', height: '100%', heightDiff: -1
      });
      $("#grid").height(document.documentElement.clientHeight - $(".toolbar").height());

      toolbar();
    });

    function toolbar() {
      var items = [];
      items.push({
        type: 'button', text: "增加", icon: 'add', click: function () {
          f_add();
        }
      });
      items.push({
        type: 'button', text: "编辑", icon: 'edit', click: function () {
          f_edit();
        }
      });
      items.push({
        type: 'button', text: "删除", icon: 'delete', click: function () {
          f_delete();
        }
      });
      $("#toolbar").ligerToolBar({
        items: items
      });

      $("#mainGrid").ligerGetGridManager()._onResize();
    }

    //enter事件
    $(document).keydown(function (e) {
      if (e.keyCode == 13) {
        f_doSearch();
      }
    });

    //编辑
    function f_edit(rowId) {
      var manager = $("#mainGrid").ligerGetGridManager();
      var rows = manager.getCheckedRows();
      if (rows && rows.length > 0) {
        BAP.overrideSelectedTabItem(_path + '/edit?id=' + rows[0]['id'], '修改节点类型');
      }
    }

    function f_add() {
      BAP.overrideSelectedTabItem(_path + '/edit', '创建节点类型');
    }

    function f_delete() {
      var manager = $("#mainGrid").ligerGetGridManager();
      var rows = manager.getCheckedRows();
      if (rows && rows.length > 0) {
        var ids = [];
        $(rows).each(function () {
          ids.push(this.id);
        });

        BAP.confirm("节点类型删除不能恢复，确定删除？", function (yes) {
          if (yes) {
            BAP.openWaitting();
            $.ajax({
              url: _path + "/delete", type: "POST", dataType: 'json',
              data: {ids: ids.toString(), rnd: Math.random()},
              success: function (responseText) {
                BAP.closeWaitting();
                if (!responseText.isError) {
                  BAP.showSuccess("删除成功！");
                  f_load();
                } else {
                  BAP.showError(responseText.msg);
                }
              },
              error: function () {
                BAP.closeWaitting();
                BAP.showError('删除失败！');
              }
            });
          }
        })
      } else {
        BAP.showWarn("请选择参数");
      }
    }

    function f_load() {
      $("#mainGrid").ligerGetGridManager().loadData(true);
    }

  </script>
</head>

<body style="padding: 0;overflow:hidden;">
<%-- 工具栏 --%>
<div id="toolbar"></div>

<%-- 表格 --%>
<div id="grid">
  <div id="mainGrid" style="margin: -1px; min-width: 680px;"></div>
</div>
</body>
</html>
